package com.engine4cloud.tdf.supervision.convert;

import com.engine4cloud.tdf.supervision.dto.AccompliceCrimeNameDTO;
import com.engine4cloud.tdf.supervision.dto.result.JzdxAccompliceCrimeNameResultDTO;
import com.engine4cloud.tdf.supervision.entity.JzdxAccompliceCrimeNameEntity;
import com.engine4cloud.tdf.supervision.entity.JzdxAccompliceEntity;
import org.apache.commons.collections4.CollectionUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;


@Mapper
public interface JzdxAccompliceCrimeNameConvert {
    JzdxAccompliceCrimeNameConvert INSTANCE = Mappers.getMapper(JzdxAccompliceCrimeNameConvert.class);

    @Mapping(target = "id", ignore = true)
    JzdxAccompliceCrimeNameEntity update(JzdxAccompliceEntity accomplice, String jtzm);

    JzdxAccompliceCrimeNameResultDTO convert(JzdxAccompliceCrimeNameEntity s);

    default JzdxAccompliceCrimeNameEntity create(JzdxAccompliceEntity s, AccompliceCrimeNameDTO crimeName) {
        JzdxAccompliceCrimeNameEntity entity = new JzdxAccompliceCrimeNameEntity();
        entity.setTafbh(s.getTafbh());
        entity.setJtzm(crimeName.getJtzm());
        entity.setTenantId(s.getTenantId());
        return entity;
    }

    default List<JzdxAccompliceCrimeNameEntity> convertList(JzdxAccompliceEntity s, List<AccompliceCrimeNameDTO> crimeNameList) {
        if (Objects.isNull(s) || CollectionUtils.isEmpty(crimeNameList)) {
            return Collections.emptyList();
        }

        List<JzdxAccompliceCrimeNameEntity> entityList = new ArrayList<>();
        crimeNameList.forEach(crimeName -> entityList.add(JzdxAccompliceCrimeNameConvert.INSTANCE.create(s, crimeName)));

        return entityList;
    }

}
